package edu.jd.movieplatform.user.comment.impl;

import edu.jd.movieplatform.search.m_point.m_PointAPI;
import edu.jd.movieplatform.user.comment.Comment;
import edu.jd.movieplatform.user.comment.CommentDto;
import edu.jd.movieplatform.user.comment.CommentService;
import edu.jd.movieplatform.user.comment.dao.CommentDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @descriptions:
 * @data: 2021/7/9 22:53
 */
@Service
@Transactional
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentDao dao;

    @Override
    public boolean CreateComment(CommentDto dto) {
        Integer commentNewNum = dao.findCommentNewNum();
        dto.setComment_host_id(commentNewNum);
        dto.setComment_sub_id(0);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        dto.setCom_time(df.format(new Date()));// new Date()为获取当前系统时间
        return dao.createComment(dto);
    }

    @Override
    public boolean ReplyComment(CommentDto dto) {
        Integer replyNew = dao.findReplyNewNum(dto.getComment_host_id());
        dto.setComment_sub_id(replyNew);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        dto.setCom_time(df.format(new Date()));// new Date()为获取当前系统时间
        return dao.createComment(dto);
    }


    @Override
    public List<Comment> GetCommentList(Integer mov_id) {
        List<Comment> list = dao.getHostCommentList(mov_id);
        for(Comment hostComment: list){
            hostComment.setChild(dao.getSubCommentList(mov_id,hostComment.getComment_host_id()));
        }
        return list;
    }
}
